package com.reggie.background.handler;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
import com.reggie.background.common.R;
import com.reggie.background.controller.EmployeeController;
import com.reggie.background.exception.CustomException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice(assignableTypes=EmployeeController.class)
@ResponseBody
public class EmployeeExceptionHandler {
    @ExceptionHandler(MySQLIntegrityConstraintViolationException.class)
    public R<String> exceptionHandler(MySQLIntegrityConstraintViolationException ex){
        String[] strs = ex.getMessage().split(" ");
        String msg = strs[2];
        msg=msg+"用户已经存在了，请勿重复添加！";

        return R.error(msg);
    }
    @ExceptionHandler(Exception.class)
    public R<String> Exception(Exception exception){
        exception.printStackTrace();
        return R.error("系统繁忙，请稍后再访问！");
    }
}
